Theory

Synthetic figures, ignoring baseline levels of each type.

2x2

library(tidyverse)
x2 <- read_csv(here::here("data", "2x2.csv"))
# 
# x2 %>% 
#   ggplot() +
#   aes(x = x, y = new, label = lab) +
#   geom_line(aes(y = baseline), linetype = 2, alpha = .5) + 
#   geom_line() +
#   geom_ribbon(aes(ymax = new, ymin = baseline), alpha = .2) + 
#   facet_wrap("outcome", nrow = 2) + 
#   geom_label() +  
#   geom_text(aes(label = lab2, y = baseline), check_overlap = T, hjust = 0, vjust = -.2) +
#   labs(y = "Change in Level Provided\n(e.g., the number of requests to agencies)",
#        title = "") + 
#   theme_void() + 
#   xlim(-.2,1.2) + 
#   ylim(-1.1,3.1) + 
#   theme(panel.border = element_rect(fill=NA),
#         axis.title.y = element_text(angle = 90))



x2 %>% 
  ggplot() +
  aes(x = x, y = new, label = lab) +
  geom_line(aes(y = baseline), linetype = 2, alpha = .5) + 
  geom_line() +
  geom_ribbon(aes(ymax = new, ymin = baseline), alpha = .2) + 
  facet_grid(priority ~ capacity) +
  geom_label() +  
  geom_text(y = 0, 
            label = "Baseline levels for new legislator\n(may differ between service and policy work)",
            aes(x = ifelse(capacity == "Capacity DOES affect behavior" & priority == "Shifting priorities DO affect behavior", 0.5, NA))) +
  labs(y = "Change in Level Provided\n(e.g., the number of requests to agencies)",
       title = "",
       x = "") + 
  #theme_minimal() + 
  xlim(-.2,1.2) + 
  ylim(-1.1,3.1) + 
  theme(panel.grid = element_blank(),
        panel.border = element_rect(fill=NA),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.background = element_blank())
Divergent Predictions for the Change in Levels of Constituency Service and Policy Work as Legislators Gain Experience and Power

Divergent Predictions for the Change in Levels of Constituency Service and Policy Work as Legislators Gain Experience and Power

# x2 %>% 
#   ggplot() +
#   aes(x = x, y = new, label = lab) +
#   #geom_point(aes(y = baseline), alpha = .5) + 
#   #geom_line() +
#   geom_segment(aes(yend = baseline, xend = x), alpha = .2, size = 20) + 
#   facet_wrap("outcome", nrow = 2) + 
#   geom_label() +  
#   geom_text(aes(label = lab2, y = baseline), check_overlap = T, hjust = 0, vjust = 1.5) +
#   labs(y = "Change in Level Provided\n(e.g., the number of requests to agencies)",
#        title = "") + 
#   theme_void() + 
#   xlim(-.1,1.1) + 
#   ylim(-1.1,3.1) + 
#   theme(panel.border = element_rect(fill=NA),
#         axis.title.y = element_text(angle = 90))

1x2

# just 
x2 %>% 
  filter(outcome %in% c("3. Only Increased Capacity Affects Behavior", "2. Only Shifting Priorities Affect Behavior")) %>% 
  mutate(outcome = str_remove(outcome, "[1-9].*Only ")) %>%
  ggplot() +
  aes(x = x, y = new, label = lab) +
  geom_line(aes(y = baseline), linetype = 2, alpha = .5) + 
  geom_line() +
  geom_ribbon(aes(ymax = new, ymin = baseline), alpha = .2) + 
  facet_wrap("outcome", nrow = 1) + 
  geom_label() +  
  geom_text(y = 0, 
            vjust = 1.1,
            label = "Baseline levels for a new legislator\n(may differ between service & policy work)",
            aes(x = ifelse(outcome == "Increased Capacity Affects Behavior", 0.5, NA))) +
  labs(y = "Change in Level Provided\n(e.g., the number of\nrequests to agencies)",
       title = "") + 
  theme_void() + 
  xlim(-.3,1.3) + 
  ylim(-1.1,1.1) + 
  theme(panel.border = element_rect(fill=NA),
        axis.title.y = element_text(angle = 90))
Divergent Predictions for the Change in Levels of Constituency Service and Policy Work as Legislators Gain Experience and Power

Divergent Predictions for the Change in Levels of Constituency Service and Policy Work as Legislators Gain Experience and Power

Data

FOIA <- read_csv(here("data/_FOIA_response_table.csv")) %>% select(-ends_with("1")) %>% 
  mutate(Department = Department %>% str_remove("Department of ")) 

FOIA %>% 
  kablebox_long()
Department Components FOIAed Records received Coded Observations
Agriculture 29 29 11 9516
Commerce 19 18 10 8038
Defense 49 13 7 9739
Education 1 1 1 4689
Energy 8 2 1 6580
Health and Human Services 15 10 7 104145
Homeland Security 14 13 12 39633
Housing and Urban Development 2 1 1 33968
Justice 23 5 3 2611
Labor 22 12 8 53341
State 1 0 0 0
the Interior 11 8 6 6079
the Treasury 7 5 5 23869
Transportation 10 7 6 26787
Veterans Affairs 6 3 2 77842
Independent Agencies 77 47 30 81053
Total 294 174 110 487890
FOIA %>% select(-Coded) %>%
  rename(N = Observations) %>% 
  kable(format = "latex", booktabs = T) %>%
  row_spec(row = 16, hline_after = TRUE) %>%
  row_spec(row = 17, bold = T) %>% 
  #kable_styling(font_size = 9, full_width = TRUE) %>% 
       write_file(here::here("tables", "FOIA.tex")) 
# can't cache data

# raw data 
load(here::here("data", "all_contacts2.Rdata"))
all_contacts2 <- all_contacts #FIXME 

load(here::here("data", "all_contacts_paper.Rdata"))

all_contacts2 %<>% mutate(type = ifelse(TYPE %in% c(1,2,3), "Constituency\nService", NA) ) %>%
  mutate(type = ifelse(TYPE %in% c(4,5), "Policy\nWork", type) )

all_contacts2$Type %<>% str_replace("Indiv. Constituent" , "Constituent (Individual)") %>% 
  str_replace("Corp. Constituent" , "Constituent (Corporate)")%>% 
  str_replace("501c3 or Local Gov." , "Constituent (501c3 or Local Gov.)")%>% 
  str_replace("Corp. Policy" , "Policy (Corporate)")%>% 
  str_replace("^Policy$" , "Policy (General)")


load(here::here("data", "dcounts_min.Rdata"))
load(here::here("data", "dcounts_tenure.Rdata"))
load(here::here("data", "dcounts_ratio.Rdata"))
load(here::here("data", "dcounts_per_district.Rdata"))


load(here::here("data", "members.Rdata"))

members %<>% mutate(member_state = member_state %>%
                     str_replace("\\) ", "-") %>%
                     str_c(")")) 


congress_years2<- function(congress){
        years<- c(congress*2 + 1787, congress*2 + 1788 ) %>% str_c(collapse = ";", sep = ";")
        return(years)
}

# FIXME members data should have years so we don't merge in observations for members in the january (final days of their last term)
# members2 <- members %>%
# mutate(year = congress %>%  congress_years2() %>% str_c(collapse = ";"))

# CAUTION THIS IS WRONG AND WILL PRINT OUT ALL YEARS IN DATA ^2
# members2$year[1]

load(here::here('data', 'agency_vars.Rdata'))

congress_years<- function(congress){
        years<- c(congress*2 + 1787, congress*2 + 1788 )
        return(years)
}

year_congress<- function(year){
    return(floor((year - 1787)/2))
}



d <- dcounts_min %>% 
  ungroup() %>% 
  mutate(type = ifelse(TYPE %in% c(1,2,3), "Constituency\nService", NA) ) %>%
  mutate(type = ifelse(TYPE %in% c(4,5), "Policy\nWork", type) )

type <- d %>% 
  group_by(type) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup()


type %>% 
  rename(type2 = type) %>%
  mutate(percent = n/sum(type$n[1:2])*100) %>% kablebox()
type2 n percent
Constituency Service 299741 80.73723
Policy Work 71514 19.26277
NA 99832 26.89041
type5 <- d %>% 
  group_by(TYPE) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() 

type5 %<>% 
  mutate(percent = n/sum(type5$n[2:6])*100)

type5 %>% kablebox()
TYPE n percent
0 4787 1.2894102
1 240639 64.8177129
2 23794 6.4090719
3 35308 9.5104443
4 13112 3.5318043
5 58402 15.7309666
6 2416 0.6507656
NA 92629 24.9502364
type2017 <- d %>% 
  filter(year> 2006, year < 2018) %>%
  group_by(type) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>%
  ungroup()

coded <- d %>% 
  mutate(coded = !is.na(type)) %>% 
  group_by(coded) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) 

coded_ratio = coded$n[2]/(sum(coded$n))

multiplier = sum(coded$n)/coded$n[2]

percent <- function(x){
  y <- x*100 
  y %<>% round() 
  return(y)}
# percent(.434534523453)

d %<>% filter(chamber != "President")

d %<>% mutate(congress = year_congress(year))




dcounts <- d %>% left_join(members)


type2xchair <- dcounts %>% 
  group_by(type, chair) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  drop_na(type, chair) %>% 
  group_by(chair) %>% 
  mutate(percent = n / sum(n) *100) 

type2xchair%>% 
  kablebox()
type chair n percent
Constituency Service 0 264161 81.70214
Constituency Service 1 35230 74.22780
Policy Work 0 59161 18.29786
Policy Work 1 12232 25.77220
type2xprestigechair <- dcounts %>% 
  group_by(type, prestige_chair) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  drop_na() %>% 
  group_by(prestige_chair) %>% 
  mutate(percent = n / sum(n) *100) 

type2xprestigechair%>% 
  kablebox()
type prestige_chair n percent
Constituency Service 0 286381 80.85725
Constituency Service 1 13010 78.35933
Policy Work 0 67800 19.14275
Policy Work 1 3593 21.64067
# prestige committee
type2xprestige <- dcounts %>% 
  group_by(type, prestige) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  drop_na() %>% 
  group_by(prestige) %>% 
  mutate(percent = n / sum(n) *100) 


type2xprestigechair%>% 
  kablebox()
type prestige_chair n percent
Constituency Service 0 286381 80.85725
Constituency Service 1 13010 78.35933
Policy Work 0 67800 19.14275
Policy Work 1 3593 21.64067
type2xchamber <- dcounts %>%
  group_by(type, chamber) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  drop_na() %>% 
  group_by(chamber) %>% 
  mutate(percent = n / sum(n) *100) 


# year
type2xyear <- dcounts %>% mutate(years = year  - yearelected) %>% 
  group_by(type, years) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  drop_na() %>% 
  group_by(years) %>% 
  mutate(percent = n / sum(n) *100) 

type2xyear %>% 
  kablebox()
type years n percent
Constituency Service 1 145812 79.88954
Constituency Service 2 153567 81.57480
Policy Work 1 36705 20.11046
Policy Work 2 34686 18.42520
# chamber averages 
dcounts %>%
  group_by(chamber, year, bioname) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  arrange(-n) %>%
  group_by(chamber) %>% 
  summarise(mean_per_year = mean(n) %>% round(0)) %>% 
  kablebox()
chamber mean_per_year
House 52
Senate 156
# per member 
dcounts %>% 
  group_by(bioname, year) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  arrange(-n) %>%
  group_by(bioname) %>% 
  mutate(mean_per_year = mean(n) %>% round(0)) %>% 
  kablebox_long()
bioname year n mean_per_year
WARNER, Mark 2014 1032 453
WEBB, James H. (Jim) 2010 849 517
CHAMBLISS, Saxby 2009 800 294
McCAIN, John Sidney, III 2015 784 380
SCHUMER, Charles Ellis (Chuck) 2012 732 486
BYRD, Robert Carlyle 2009 691 510
NELSON, Clarence William (Bill) 2010 668 455
MIKULSKI, Barbara Ann 2010 657 393
SCHUMER, Charles Ellis (Chuck) 2010 650 486
GRASSLEY, Charles Ernest 2010 649 383
WARNER, Mark 2015 640 453
BYRD, Robert Carlyle 2008 621 510
McCAIN, John Sidney, III 2016 620 380
GILLIBRAND, Kirsten 2013 611 332
WEBB, James H. (Jim) 2009 603 517
WEBB, James H. (Jim) 2008 599 517
NELSON, Clarence William (Bill) 2009 596 455
GRASSLEY, Charles Ernest 2011 595 383
NELSON, Clarence William (Bill) 2011 580 455
GILLIBRAND, Kirsten 2012 572 332
DURBIN, Richard Joseph 2009 561 272
SCHUMER, Charles Ellis (Chuck) 2009 561 486
LUGAR, Richard Green 2010 558 410
SCHUMER, Charles Ellis (Chuck) 2016 554 486
NELSON, Clarence William (Bill) 2013 553 455
LUGAR, Richard Green 2011 541 410
MIKULSKI, Barbara Ann 2013 541 393
MANCHIN, Joe, III 2011 525 260
NELSON, Clarence William (Bill) 2012 522 455
MIKULSKI, Barbara Ann 2011 521 393
SCHUMER, Charles Ellis (Chuck) 2011 507 486
WOLF, Frank Rudolph 2010 502 377
GILLIBRAND, Kirsten 2011 501 332
WOLF, Frank Rudolph 2009 496 377
GILLIBRAND, Kirsten 2014 492 332
WARNER, Mark 2013 487 453
WARNER, Mark 2016 486 453
SCHUMER, Charles Ellis (Chuck) 2013 482 486
WARNER, Mark 2011 482 453
WOLF, Frank Rudolph 2011 480 377
MIKULSKI, Barbara Ann 2014 478 393
SHELBY, Richard C. 2011 476 284
RUBIO, Marco 2017 475 264
LUGAR, Richard Green 2009 466 410
KIRK, Mark Steven 2011 465 220
McCAIN, John Sidney, III 2010 465 380
SCHUMER, Charles Ellis (Chuck) 2014 464 486
GRASSLEY, Charles Ernest 2012 462 383
DURBIN, Richard Joseph 2008 458 272
WARNER, Mark 2012 456 453
NELSON, Clarence William (Bill) 2016 455 455
TOOMEY, Patrick Joseph 2015 453 343
SPECTER, Arlen 2008 451 332
NELSON, Clarence William (Bill) 2014 450 455
OBAMA, Barack 2008 450 308
WEBB, James H. (Jim) 2011 449 517
KIRK, Mark Steven 2013 442 220
BROWN, Sherrod 2012 440 284
TOOMEY, Patrick Joseph 2016 433 343
SPECTER, Arlen 2010 430 332
CHAMBLISS, Saxby 2008 429 294
LUGAR, Richard Green 2008 429 410
GRASSLEY, Charles Ernest 2009 425 383
BROWN, Sherrod 2011 423 284
GILLIBRAND, Kirsten 2016 422 332
McCAIN, John Sidney, III 2017 422 380
CASEY, Robert (Bob), Jr.  2012 419 260
McCAIN, John Sidney, III 2009 417 380
MIKULSKI, Barbara Ann 2012 417 393
SCHUMER, Charles Ellis (Chuck) 2008 412 486
GRASSLEY, Charles Ernest 2015 410 383
MIKULSKI, Barbara Ann 2009 410 393
BOOKER, Cory Anthony 2015 408 265
RUBIO, Marco 2016 408 264
SHELBY, Richard C. 2009 403 284
CORNYN, John 2009 402 265
GRASSLEY, Charles Ernest 2013 401 383
SCHUMER, Charles Ellis (Chuck) 2015 399 486
WOLF, Frank Rudolph 2012 397 377
SHELBY, Richard C. 2012 396 284
REID, Harry 2011 391 212
DURBIN, Richard Joseph 2010 387 272
SCHUMER, Charles Ellis (Chuck) 2017 387 486
SHELBY, Richard C. 2008 386 284
BURR, Richard M. 2016 383 205
WOLF, Frank Rudolph 2008 383 377
NELSON, Clarence William (Bill) 2007 382 455
GILLIBRAND, Kirsten 2010 380 332
CASEY, Robert (Bob), Jr.  2011 377 260
MANCHIN, Joe, III 2014 377 260
HAGAN, Kay 2014 375 274
GILLIBRAND, Kirsten 2015 374 332
MANCHIN, Joe, III 2012 374 260
GRAHAM, Lindsey O. 2014 373 202
TOOMEY, Patrick Joseph 2017 373 343
BYRD, Robert Carlyle 2010 372 510
GRASSLEY, Charles Ernest 2014 372 383
NELSON, Clarence William (Bill) 2008 372 455
CASEY, Robert (Bob), Jr.  2013 368 260
GRASSLEY, Charles Ernest 2016 368 383
# per member HOUSE
dcounts %>% 
  filter(chamber == "House") %>% 
  group_by(bioname, year) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  arrange(-n) %>%
  group_by(bioname) %>% 
  mutate(mean_per_year = mean(n) %>% round(0)) %>% 
  kablebox_long()
bioname year n mean_per_year
WOLF, Frank Rudolph 2010 502 377
WOLF, Frank Rudolph 2009 496 377
WOLF, Frank Rudolph 2011 480 377
WOLF, Frank Rudolph 2012 397 377
WOLF, Frank Rudolph 2008 383 377
FRANK, Barney 2010 346 290
GARRETT, Scott 2014 342 145
FRANK, Barney 2009 335 290
McCAUL, Michael T. 2012 334 202
GARRETT, Scott 2016 333 145
COMSTOCK, Barbara J. 2016 332 208
McCAUL, Michael T. 2010 329 202
SHIMKUS, John M. 2010 326 156
FRANK, Barney 2011 323 290
SESTAK, Joe 2010 313 216
McCAUL, Michael T. 2009 308 202
RODRIGUEZ, Ciro D. 2008 306 215
DENT, Charles W. 2010 303 132
SHIMKUS, John M. 2009 303 156
GOODLATTE, Robert William 2014 302 172
EDWARDS, Donna F. 2009 295 96
CARTWRIGHT, Matt 2014 287 139
CARTER, Buddy 2016 284 191
RODRIGUEZ, Ciro D. 2009 284 215
McCAUL, Michael T. 2008 283 202
SHIMKUS, John M. 2008 280 156
WOLF, Frank Rudolph 2013 279 377
McCAUL, Michael T. 2011 273 202
PAUL, Ronald Ernest 2010 268 156
FILNER, Bob 2010 264 131
VAN HOLLEN, Christopher 2011 262 157
FRANK, Barney 2012 259 290
GOODLATTE, Robert William 2013 257 172
WOLF, Frank Rudolph 2014 256 377
ALEXANDER, Rodney 2010 254 204
ALEXANDER, Rodney 2012 253 204
FRANK, Barney 2008 253 290
PAUL, Ronald Ernest 2009 252 156
DENT, Charles W. 2011 248 132
SESTAK, Joe 2009 247 216
ALEXANDER, Rodney 2014 245 204
COMSTOCK, Barbara J. 2015 245 208
FORBES, J. Randy 2015 237 154
VAN HOLLEN, Christopher 2010 236 157
GOODLATTE, Robert William 2016 235 172
RODRIGUEZ, Ciro D. 2010 234 215
CHAFFETZ, Jason 2016 232 62
ALEXANDER, Rodney 2013 228 204
STEFANIK, Elise M 2016 227 181
STEFANIK, Elise M 2017 224 181
WOLF, Frank Rudolph 2007 223 377
FRANK, Barney 2007 222 290
TIPTON, Scott 2015 222 111
GARRETT, Scott 2015 217 145
SHEA-PORTER, Carol 2014 217 76
MURPHY, Timothy 2014 216 87
CARTER, Buddy 2015 215 191
RAHALL, Nick Joe, II 2013 214 126
MILLER, Jefferson B. (Jeff) 2014 212 65
SCOTT, Austin 2016 212 120
ALEXANDER, Rodney 2011 211 204
FORBES, J. Randy 2016 210 154
CARTWRIGHT, Matt 2015 209 139
DAVIS, Rodney 2018 209 136
VISCLOSKY, Peter 2012 209 145
ACKERMAN, Gary Leonard 2010 207 116
MURPHY, Patrick 2014 207 78
GRIFFITH, H. Morgan 2015 206 143
KINGSTON, Jack 2012 206 142
BENISHEK, Dan 2013 205 108
DAVIS, Rodney 2016 205 136
MOORE, Dennis 2009 205 111
PALLONE, Frank, Jr.  2016 205 110
GOODLATTE, Robert William 2012 204 172
VISCLOSKY, Peter 2009 204 145
ALEXANDER, Rodney 2009 203 204
STEFANIK, Elise M 2015 200 181
GRAHAM, Gwendolyn (Gwen) 2016 198 190
PALLONE, Frank, Jr.  2017 198 110
SCOTT, Austin 2014 198 120
VAN HOLLEN, Christopher 2009 197 157
COLLINS, Chris 2018 196 110
LAMPSON, Nicholas V. 2008 196 124
DAVIS, Lincoln 2009 195 156
DAVIS, Rodney 2017 195 136
OWENS, William 2013 192 138
RICE, Kathleen Maura 2015 192 112
WITTMAN, Robert J. 2015 192 104
GRIFFITH, H. Morgan 2014 190 143
DAVIS, Lincoln 2008 189 156
GOODLATTE, Robert William 2015 189 172
GARRETT, Scott 2013 188 145
OWENS, William 2011 188 138
SARBANES, John 2010 188 93
SCOTT, Robert C. 2015 188 101
UPTON, Frederick Stephen 2012 188 96
UPTON, Frederick Stephen 2013 188 96
FORBES, J. Randy 2013 187 154
VISCLOSKY, Peter 2013 187 145
PITTS, Joseph R. 2009 185 109
# per member VA-10
dcounts %>% 
  filter(cqlabel == "(VA-10)") %>% 
  group_by(bioname, year) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  arrange(year) %>%
  group_by(bioname) %>% 
  mutate(mean_per_year = mean(n) %>% round(0)) %>% 
  kablebox_long()
bioname year n mean_per_year
WOLF, Frank Rudolph 2007 223 377
WOLF, Frank Rudolph 2008 383 377
WOLF, Frank Rudolph 2009 496 377
WOLF, Frank Rudolph 2010 502 377
WOLF, Frank Rudolph 2011 480 377
WOLF, Frank Rudolph 2012 397 377
WOLF, Frank Rudolph 2013 279 377
WOLF, Frank Rudolph 2014 256 377
COMSTOCK, Barbara J. 2015 245 208
COMSTOCK, Barbara J. 2016 332 208
COMSTOCK, Barbara J. 2017 160 208
COMSTOCK, Barbara J. 2018 97 208
dcounts %>% 
  group_by(bioname, year) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  arrange(n) %>%
  group_by(bioname) %>% 
  mutate(mean_per_year = mean(n) %>% round(0)) %>% 
  #FIXME 
  filter(n > 4) %>% 
  kablebox_long()
bioname year n mean_per_year
AKIN, W. Todd 2008 5 16
AMODEI, Mark E. 2018 5 14
BARROW, John 2007 5 65
BIDEN, Joseph Robinette, Jr.  2009 5 27
BISHOP, Robert (Rob) 2007 5 29
CROWLEY, Joseph 2018 5 33
DAVIS, Danny K. 2018 5 25
GARRETT, Thomas Alexander Jr.  2018 5 13
HUIZENGA, Bill 2018 5 26
JINDAL, Bobby 2008 5 22
KENNEDY, Edward Moore (Ted) 2010 5 128
KHANNA, Rohit 2018 5 10
LAMB, Conor 2017 5 6
LEVIN, Sander Martin 2018 5 40
LEWIS, John R. 2018 5 54
LYNCH, Stephen F. 2018 5 26
MARSHALL, Roger Wayne 2018 5 10
MULVANEY, Mick 2017 5 20
NUNNELEE, Alan 2015 5 34
POMEROY, Earl Ralph, III 2007 5 23
SALAZAR, Kenneth Lee 2010 5 42
SÁNCHEZ, Linda T. 2018 5 21
SHULER, Heath 2007 5 27
TITUS, Alice (Dina) 2018 5 30
TORRES, Norma Judith 2018 5 14
VARGAS, Juan 2018 5 32
WATERS, Maxine 2018 5 23
WELLER, Gerald C. (Jerry) 2007 5 8
ABERCROMBIE, Neil 2010 6 18
BACHMANN, Michele 2007 6 31
BIDEN, Joseph Robinette, Jr.  2010 6 27
BUTTERFIELD, George Kenneth, Jr. (G.K.) 2018 6 28
CALVERT, Ken 2018 6 38
CLYBURN, James Enos 2008 6 16
GRAVES, Samuel 2018 6 56
GREEN, Al 2017 6 28
KILPATRICK, Carolyn Cheeks 2007 6 13
KUSTOFF, David 2018 6 12
LaHOOD, Darin 2015 6 31
LAWRENCE, Brenda L 2018 6 29
LEWIS, Jason Mark 2018 6 8
LOWENTHAL, Alan 2018 6 46
MARCHANT, Kenny 2007 6 23
MARCHANT, Kenny 2018 6 23
MARSHALL, Jim 2007 6 48
MEEHAN, Martin Thomas 2007 6 3
MOONEY, Alex X. 2018 6 13
NAPOLITANO, Grace Flores 2007 6 15
NAPOLITANO, Grace Flores 2018 6 15
PALMER, Gary James 2018 6 18
PETERSON, Collin Clark 2018 6 26
PRICE, David Eugene 2018 6 46
ROYBAL-ALLARD, Lucille 2018 6 27
RUSH, Bobby L. 2018 6 43
SALAZAR, Kenneth Lee 2009 6 42
SESSIONS, Jefferson Beauregard III (Jeff) 2017 6 120
SMITH, Adrian 2018 6 24
STEWART, Chris 2018 6 18
WICKER, Roger F. 2007 6 55
ADAMS, Alma 2018 7 25
BECERRA, Xavier 2008 7 18
BISHOP, Sanford Dixon, Jr.  2007 7 38
BONAMICI, Suzanne 2018 7 22
CHENEY, Liz 2018 7 11
ESTES, Ron 2017 7 14
GABBARD, Tulsi 2018 7 42
GARAMENDI, John 2009 7 60
GRIJALVA, Raúl M. 2018 7 63
GUTIÉRREZ, Luis V. 2007 7 16
HARMAN, Jane L. 2011 7 20
ISSA, Darrell 2018 7 81
JEFFRIES, Hakeem 2018 7 14
JONES, Stephanie Tubbs 2007 7 22
KNIGHT, Steve 2018 7 28
LUCAS, Frank D. 2018 7 16
McCOLLUM, Betty 2008 7 30
PORTER, Jon C. 2007 7 8
PRYCE, Deborah D. 2008 7 9
ROONEY, Thomas J. 2018 7 32
SEWELL, Terri 2018 7 45
SULLIVAN, John 2008 7 23
SWALWELL, Eric 2018 7 36
TURNER, Robert L. 2011 7 26
WEXLER, Robert 2010 7 64
AKIN, W. Todd 2007 8 16
BARRASSO, John A. 2007 8 52
BEATTY, Joyce 2018 8 33
BECERRA, Xavier 2010 8 18
BISHOP, Robert (Rob) 2008 8 29
BLUMENAUER, Earl 2018 8 34
BOEHNER, John Andrew 2016 8 56
BUCHANAN, Vernon G. 2007 8 43
CLARKE, Yvette Diane 2007 8 31
CLAY, William Lacy, Jr.  2018 8 56
CONAWAY, K. Michael 2018 8 23
COOPER, James Hayes Shofner 2018 8 19
CORREA, Jose Luis 2018 8 13
COSTA, Jim 2018 8 28
CURTIS, John R. 2018 8 4
DINGELL, Debbie 2018 8 26

Example

Rep. Barbara Comstock worked in Rep. Frank Wolf’s congressional office for five years, described him as a “longtime mentor,” and claimed that Wolf first urged her to run for office. He endoresed and campaigned with her.

Notice several patterns - dip in constituncy service when Wolf is no longer running for re-eleiction - further dip with transition - quick rebound as Comstock gets her office in order - inheriting a highly-effective office, Comstock is far above average house member

cq <- "(VA-10)"

dcounts %>% 
  group_by(member_state, year, chamber, cqlabel) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  group_by(chamber) %>% 
  mutate(mean_per_chamber = mean(n) %>% round(0)) %>% 
  filter(cqlabel == cq, year > 2007, year <2017) %>% 
  ggplot() +
  aes(x = year, y = n, fill = member_state) + 
  geom_col(alpha = .5, position = "dodge") +
  geom_hline(aes(yintercept = mean_per_chamber), linetype = 2) + 
  geom_text(aes(y = mean_per_chamber), x = 2007.5, label = "House mean", min.segment.length = 0, size = 3, fill = NA, vjust = -.3, hjust = 0) + 
  scale_x_continuous(breaks = seq(2008, 2016, 1)) +
  labs(x = "",
       y = "Number of Requests", 
       fill = cq %>% str_remove_all("\\(|\\)")) + 
  theme_minimal() + 
  theme(panel.grid.major.x =  element_blank(),
        panel.grid.minor.x =  element_blank(),
        axis.text.x = element_text(angle = 45))

cq <- "(NY-07)"
CHAMBER <- "House"
dcounts %>% 
  group_by(member_state, year, chamber, cqlabel) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  group_by(chamber) %>% 
  mutate(mean_per_chamber = mean(n) %>% round(0)) %>% 
  ggplot() +
  aes(x = year, y = n, 
      fill = member_state %>% str_replace("-.*", "\\)")) + 
  geom_col(alpha = .5, position = "dodge") +
  geom_hline(aes(yintercept = mean_per_chamber), linetype = 2) + 
  geom_text(aes(y = mean_per_chamber), x = 2007.5, label = "Chamber average", min.segment.length = 0, size = 3, fill = NA, vjust = 1.3, hjust = 0) + 
  scale_x_continuous(breaks = seq(2007, 2017, 1)) +
  labs(x = "",
       y = "Number of Requests", 
       fill = str_c(CHAMBER, "-", cq) %>% str_remove_all("\\(|\\)") ) + 
  theme_minimal() + 
  theme(panel.grid.major.x =  element_blank(),
        panel.grid.minor.x =  element_blank(),
        axis.text.x = element_text(angle = 45))

cq <- "(NY-14)"
CHAMBER <- "House"
dcounts %>% 
  group_by(member_state, year, chamber, cqlabel) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  group_by(chamber) %>% 
  mutate(mean_per_chamber = mean(n) %>% round(0)) %>% 
  filter(cqlabel == cq, year > 2007, year <2019) %>% 
  ggplot() +
  aes(x = year, y = n, 
      fill = member_state %>% str_replace("-.*", "\\)")) + 
  geom_col(alpha = .5, position = "dodge") +
  geom_hline(aes(yintercept = mean_per_chamber), linetype = 2) + 
  geom_text(aes(y = mean_per_chamber), x = 2007.5, label = "Chamber average", min.segment.length = 0, size = 3, fill = NA, vjust = 1.3, hjust = 0) + 
  scale_x_continuous(breaks = seq(2008, 2017, 1)) +
  labs(x = "",
       y = "Number of Requests", 
       fill = str_c(CHAMBER, "-", cq) %>% str_remove_all("\\(|\\)") ) + 
  theme_minimal() + 
  theme(panel.grid.major.x =  element_blank(),
        panel.grid.minor.x =  element_blank(),
        axis.text.x = element_text(angle = 45))

case_study <- function(cq){

  CHAMBER <- filter(members, cqlabel == cq) %>% 
    .$chamber %>% .[1]

dcounts %>% 
  group_by(member_state, year, chamber, cqlabel) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
  ungroup() %>% 
  group_by(chamber) %>% 
  mutate(mean_per_chamber = mean(n) %>% round(0)) %>% 
  filter(cqlabel == cq, year > 2007, year <2017) %>% 
  ggplot() +
  aes(x = year, y = n, 
      fill = member_state %>% str_replace("-.*", "\\)")) + 
  geom_col(alpha = .5, position = "dodge") +
  geom_hline(aes(yintercept = mean_per_chamber), linetype = 2) + 
  geom_text(aes(y = mean_per_chamber), x = 2007.5, label = "Chamber average", min.segment.length = 0, size = 3, fill = NA, vjust = 1.3, hjust = 0) + 
  scale_x_continuous(breaks = seq(2008, 2016, 1)) +
  labs(x = "",
       y = "Number of Requests", 
       fill = str_c(CHAMBER, "-", cq) %>% str_remove_all("\\(|\\)") ) + 
  theme_minimal() + 
  theme(panel.grid.major.x =  element_blank(),
        panel.grid.minor.x =  element_blank(),
        axis.text.x = element_text(angle = 45))
  
ggsave(str_c("figs/districts/", cq, ".png"), 
       width = 5.3,
  height = 2.5,
  dpi = 1000)
} 

case_study("(NY-14)")

cases <- unique(members$cqlabel) #%>% head()

# map(cases, case_study )

Between February 2017 and February 2021, we received data on 471087 instances of members of Congress contacting federal agencies. We focus on requests made from 2007-2017, resulting in a data set of 452323 contacts from members of Congress with federal agencies.

Requests by percentile

dcounts %>% 
    group_by(member_state, chamber, year) %>% summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>%
  group_by(member_state, chamber) %>% 
  summarise(mean = mean(n)) %>% 
  ungroup() %>% 
    group_by(chamber) %>% 
  mutate(Percentile = ntile(mean, 100),
         rank = dense_rank(-mean)) %>% 
  arrange(-Percentile) %>% 
  dplyr::select(member_state, Percentile, mean, chamber,rank) %>% distinct() %>% 
    ggplot() + 
    geom_col(aes(x = Percentile, y = mean), 
             color = "grey", 
             width = .000001,
             fill = "black",
             position = "dodge") + 
  geom_point(aes(x = Percentile, y = mean), color = "light blue") + 
  geom_text(aes(x = Percentile, y = mean, label = ifelse(rank <14 | Percentile < 30, member_state, "")), check_overlap = T, 
                  size = 2,
                  hjust = "inward") + 
  theme_minimal() + 
  labs(#title = "Average Legislator Requests per Year by Percentile",
       x = "Percentile Within Chamber",
       y = "Average Requests per Year") +     facet_grid(. ~ chamber , scales = "free_y") 

Requests by year

dcounts %<>% 
  group_by(bioname, year) %>% 
  mutate(per_bioname_year = sum(per_icpsr_chamber_year_agency_type)) %>%
  ungroup() %>% 
  group_by(year) %>%
  #mutate(per_bioname_year = per_bioname_year - mean(per_bioname_year)) %>% 
  ungroup() 

schumer2013 <- dcounts %>% filter(bioname == "SCHUMER, Charles Ellis (Chuck)",
                   year == 2013) %>% .$per_bioname_year %>% unique()

cruz2013 <- dcounts %>% filter(bioname == "CRUZ, Rafael Edward (Ted)",
                   year == 2013) %>% .$per_bioname_year %>% unique()

mcconnell2013 <- dcounts %>% filter(bioname == "McCONNELL, Addison Mitchell (Mitch)",
                   year == 2013) %>% .$per_bioname_year %>% unique()


p <- dcounts %>% 
  filter(year > 2006, year <2018) %>%
  distinct(bioname, per_bioname_year, year, chamber) %>% 
  filter(per_bioname_year > 0) %>% 
  ggplot() + 
  geom_line(aes(x = year, 
                y = per_bioname_year, 
                group = bioname, 
                color = chamber), 
            alpha = .1) +
  geom_line(aes(x = year, 
                group = bioname, 
                color = chamber,
                y = ifelse(bioname == "SCHUMER, Charles Ellis (Chuck)", per_bioname_year, NA))) + 
  geom_label(x = 2013, 
             y = schumer2013, 
             label = "Chuck Schumer") +
  geom_line(aes(x = year, group = bioname, color = chamber,
                y = ifelse(bioname == "CRUZ, Rafael Edward (Ted)", per_bioname_year, NA))) + 
  geom_label(x = 2013, 
             y = cruz2013, 
             label = "Ted Cruz") +
  geom_line(aes(x = year, group = bioname, color = chamber,
                y = ifelse(bioname == "McCONNELL, Addison Mitchell (Mitch)", per_bioname_year, NA))) + 
  geom_label(x = 2013, 
             y = mcconnell2013, 
             label = "Mitch McConnell") +
  labs(x = "",
       color = " ",
       y = paste("Requests per Legislator per Year"),
       title = "") +
  scale_x_continuous(breaks = unique(dcounts$year)) + 
  scale_color_viridis_d(begin = 0, end = .6, option = "cividis", direction = -1) +
  theme_minimal() + 
  theme(panel.background = element_blank(),
        axis.ticks = element_blank(),
        axis.text.x = element_text(angle = 30, vjust = 0)) 

# FIXME, this takes a long time 
p

ggsave(here::here("figs/counts-per-year.pdf"), p, height=3, width=6)

Requests by state population

library(scales)


dcounts %>% 
  filter(chamber == "Senate") %>% 
    group_by(member_state, year, pop2010) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>% 
    group_by(member_state, pop2010) %>%
  summarise(mean = mean(n)) %>% ungroup() %>% 
    ggplot() + 
    geom_point(aes(x = pop2010, y = mean), color = "light blue") + 
    geom_smooth(aes(x = pop2010, y = mean)) + 
  geom_text_repel(aes(x = pop2010, 
                y = mean, 
                label = ifelse(mean > 260 |# & log(pop2010) < 17.4 | 
                                 mean < 80 & (log(pop2010) > 17 | log(pop2010) <14), 
                               member_state, 
                               "")), 
            seed = 44,
            check_overlap = T, 
            min.segment.length = 0,
            size = 2.5) + theme_bw() +
  labs(title = "",
       x = "State Population (log scale)",
       y = "Average Number of Requests per Year") +
  scale_x_log10(labels = comma)


Types of requests

81% of the average legislators’ contacts with agencies are about constituency service.

19% of the average legislators’ contacts with agencies are about policy work.

type n
Constituency Service 299741
Policy Work 71514
NA 99832

We classify legislator requests into five overall types:

All data:

# paper figure 
type_totals <- all_contacts2 %>% 
  filter(Type != "To be coded") %>%  
  mutate(total = n()) %>% 
  group_by(Type, total, type) %>% 
  summarise(nT = n()) %>% 
  mutate(percent = paste0(nT, " = ", 100*round(nT/total, 2), "%"),
         Type = str_c(Type, "\n    ", percent)) %>% 
  ungroup() %>% 
  group_by(type) %>% 
  mutate(nt = sum(nT),
         percent_t = paste0(100*round(nt/total, 2), "%"))

type_totals %<>% mutate(Type = Type %>% 
                          str_replace_all("\\)", "") %>% 
                          str_replace_all(" \\(", ",\n") )

# horizontal
type_totals %>% 
  ggplot() + 
  geom_col(alpha = .7,aes(x = Type, fill = type, y = nT) ) + 
  scale_y_continuous(breaks = seq(0,500000, 50000), limits = c(0,300000)) + 
  labs(x = "",
       fill = "",
       y = paste("Number of Contacts"),
       title = "") +
  #geom_text(aes(label = Type, x = Type,y = nT) ) + 
  theme(panel.border = element_blank(),
        panel.grid.major.x = element_blank(),
        axis.ticks = element_blank(),
        #axis.text.x.top = element_text(),
        legend.position ="none") + 
  ggpubr::geom_bracket(
    xmin = type_totals$Type[1], xmax = type_totals$Type[3], 
    y.position = 260000,
    label = paste(type_totals$percent_t[1], "Constituency Service" ),
    #hjust = 1,
    vjust = -1
  ) + 
  ggpubr::geom_bracket(
    xmin = type_totals$Type[4], xmax = type_totals$Type[5], 
    y.position = 75000,
    label = paste(type_totals$percent_t[5], "Policy Work"),
    #hjust = 1,
    vjust = -1
  )+ 
  scale_fill_viridis_d(option = "cividis", end = .8, direction = -1)

all_contacts2 %>% 
  filter(Type != "To be coded") %>%  
  mutate(total = n()) %>% 
  group_by(Type, total, type) %>% 
  summarise(nT = n()) %>% 
  mutate(percent = paste0(nT, " = ", 100*round(nT/total, 2), "%"),
         Type = str_c(Type, "\n    ", percent)) %>% 
  ungroup() %>% 
  #distinct(type, Type, nT)
  ggplot() + 
  geom_col(alpha = .7,aes(x = type, fill = Type, y = nT), position ="stack") + 
  #coord_flip() + 
  scale_y_continuous(labels = scales::comma) + 
  labs(x = "",
       fill = "",
       y = paste("Number of Contacts\nN =", sum(nrow(all_contacts2))),
       title = "") +
  #theme_void() + 
  theme(panel.border = element_blank(),
        panel.grid.major.x = element_blank(),
        axis.ticks = element_blank(),
        axis.text.x = element_text())

Horizontal format:

type_totals %<>% 
  #distinct(type, Type, nT)
  mutate(Type = Type %>% str_replace(",\n", ", "))

type_totals %>% 
  ggplot() + 
  geom_col(alpha = .7,aes(x = Type, fill = type, y = nT/1000) ) + 
  coord_flip() + 
  scale_y_continuous(breaks = seq(0,500, 50), limits = c(0,500)) + 
  labs(x = "",
       fill = "",
       y = paste("Number of Contacts (Thousands)"),
       title = "") +
  #theme_void() + 
  theme(panel.border = element_blank(),
        panel.grid.major.y = element_blank(),
        axis.ticks = element_blank(),
        axis.text.x.top = element_text(),
        legend.position ="none") + 
  ggpubr::geom_bracket(
    xmin = type_totals$Type[1], xmax = type_totals$Type[3], y.position = 300,
    label = paste(type_totals$percent_t[1], type_totals$type[1]),
    hjust = -.3,
    vjust = 1.5,
    label.size = 3.5
  ) + 
  ggpubr::geom_bracket(
    xmin = type_totals$Type[4], xmax = type_totals$Type[5], y.position = 100,
    label = paste(type_totals$percent_t[5], type_totals$type[5]),
    hjust = -.3,
    vjust = 1,
    label.size = 3.5
  )

all_contacts2 %>% 
  filter(Type != "To be coded") %>%  
  mutate(total = n()) %>% 
  group_by(Type, total, type) %>% 
  summarise(nT = n()) %>% 
  mutate(percent = paste0(nT, " = ", 100*round(nT/total, 2), "%"),
         Type = str_c(Type, "\n    ", percent)) %>% 
  ungroup() %>% 
  #distinct(type, Type, nT)
  ggplot() + 
  geom_col(alpha = .7,aes(x = type, fill = Type, y = nT/1000), position ="stack") + 
  coord_flip() + 
  scale_y_continuous(breaks = seq(0,500, 50)) + 
  labs(x = "",
       fill = "",
       y = paste("Number of Contacts (Thousands)"),
       title = "") +
  #theme_void() + 
  theme(panel.border = element_blank(),
        panel.grid.major.y = element_blank(),
        axis.ticks = element_blank(),
        axis.text.x.top = element_text())

2007-2017 data:

N <- all_contacts2 %>% 
  filter(year <2018,
         year > 2006) %>% 
  nrow()

all_contacts2 %>% 
  filter(Type != "To be coded",
         year <2018,
         year > 2006) %>%  
    mutate(total = n()) %>% 
  group_by(Type, total, type) %>% 
  summarise(nT = n()) %>% 
  mutate(percent = paste0(nT, " = ", 100*round(nT/total, 2), "%"),
         Type = str_c(Type, "\n    ", percent)) %>% 
  ungroup() %>% 
  #distinct(type, Type, nT)
  ggplot() + 
  geom_col(alpha = .7,aes(x = type, fill = Type, y = nT/1000), position ="stack") + 
  coord_flip() + 
  scale_y_continuous(breaks = seq(0,500, 50)) + 
  labs(x = "",
       fill = "",
       y = paste("Number of Contacts (Thousands)\nN =", N),
       title = "") +
  #theme_void() + 
  theme(panel.border = element_blank(),
        panel.grid.major.y = element_blank(),
        axis.ticks = element_blank(),
        axis.text.x.top = element_text())


Requests by institutional position

The first plot is the contacts we have coded. The second assumes these ratios hold for uncoded letters.

chairs <- all_contacts %>% distinct(icpsr, chair, year) 

d %<>% left_join(chairs) %>% 
  mutate(chair = chair %>%
           replace_na(0),
         Chair = ifelse(chair == 1, "Committee Chair", " Non-Chair"))

chair <- d %>% 
  group_by(type, year, icpsr, Chair) %>% 
  summarise(n = sum(per_icpsr_chamber_year_agency_type)) %>%
  group_by(type, Chair) %>% 
  summarise(mean = mean(n)) %>% 
  ungroup() %>%
  filter(!is.na(type))

chair %>% 
  ggplot()  + 
  aes(x = type, y = mean) +
  geom_col(alpha = .7,position = "dodge") + 
  facet_wrap("Chair") + 
  labs(x = "", # "Type of Legislator Request to Agency",
       y = "Average Requests per Year") +
  theme(panel.grid.major.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.x = element_blank())
Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

chair %>% 
  # assuming consistant proportions to uncoded data 
  mutate(mean = mean*multiplier) %>% 
  ggplot()  + 
  aes(x = type, y = mean) +
  geom_col(alpha = .7,position = "dodge") + 
  facet_wrap("Chair") + 
  labs(x = "Type of Legislator Request to Agency",
       y = "Average Requests per Year") +
  theme(panel.grid.major.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.x = element_blank())
Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Level

Member-level

TODO

  • [ x ] members.Rdata going back to most senior member’s first Congress in “data/nominate.Rdata”
  • [ x ] what to do with party and chamber switchers? Drop them from counts.
#load(here::here('data', 'dcounts_min.Rdata'))

##creating the aggregate count variable
## one obs per agency, member, year 
d <- dcounts_min %>% 
  group_by(agency, icpsr, chamber, year) %>% 
  summarise(perYear = sum(per_icpsr_chamber_year_agency_type)) 

# dcounts_min %>% 
#   mutate(type2 = ifelse(TYPE %in% c(1,2,3), "policy", NA ),
#          type2 = ifelse(TYPE %in% c(4,5), "constituent", type2)) %>% 
#   group_by(type2, agency, icpsr, chamber, year) %>% 
#   # 2-type counts 
#   mutate(perYear_type2 = sum(per_icpsr_chamber_year_agency_type),
#          # versions with NAs for models
#          perYear_con = ifelse(type2 == "constituent", perYear_type2),
#          perYear_pol = ifelse(type2 == "policy", perYear_type2))
#   

# constituency service
d_sub <- dcounts_min %>%
  filter(TYPE %in% c(1, 2, 3)) %>%
  group_by(agency, icpsr, chamber, year) %>%
  summarise(perYear_con = sum(per_icpsr_chamber_year_agency_type))

# policy
d_sub2<- dcounts_min %>%
  subset(TYPE %in% c(4, 5)) %>%
  group_by(agency, icpsr, chamber, year) %>%
  summarise(perYear_pol = sum(per_icpsr_chamber_year_agency_type))


d %<>% left_join(d_sub) %>% left_join(d_sub2)

# congress
d$congress <- year_congress(d$year)

d %<>% left_join(members %>% 
                 select(congress, icpsr, party,party_code, state_abbrev, district_code, nominate.dim1, presidents_party, female, chair, ranking_minority, party_leader, party_whip, majority, prestige, prestige_chair, yearelected, state), by = c('congress', 'icpsr'))

#FIXME this should all be in members data 
# nom <- read_csv(here::here('data', 'nominate_data.csv'))
nom2<- members %>% 
  group_by(icpsr) %>% 
  summarise(first_cong = min(congress))

nom2$first_year <- 1787 + 2*nom2$first_cong

df<- left_join(d, nom2, by ='icpsr' )
#/FIXME 

# Tenure vars 
df$tenure<- df$year - df$first_year
df$first<- ifelse(df$tenure==0, 1, 0)
df$second<- ifelse(df$tenure==1, 1, 0)
df$third<- ifelse(df$tenure==2, 1, 0)
df$fourth<- ifelse(df$tenure==3, 1, 0)
df$fifth<- ifelse(df$tenure==4, 1, 0)
df$sixth<- ifelse(df$tenure==5, 1, 0)

# colnames(agency_vars)
df %<>% 
  #select(-oversight_committee, -oversight_committee_chair) %>% #FIXME these should be the same
  left_join(agency_vars %>% 
                    select(agency, icpsr, chamber, year, oversight_committee,
                           oversight_committee_chair), by = c('agency', 'icpsr', 'year', 'chamber')
            )

df$icpsr_agency<- paste(df$agency, df$icpsr, sep='_')
df$agency_year<- paste(df$agency, df$year, sep='_')

# tenure 
df %<>% ungroup() %>% 
  group_by(icpsr) %>% 
  mutate(max_year = max(tenure)) 

df$survive <- ifelse((df$chamber=='House' & df$max_year>1)| (df$chamber=='Senate' & df$max_year>5),1, 0 )


##purging repeated values 
#FIXME repeats are probably chamber switchers
df %<>% 
  add_count(icpsr, year, agency, chamber, 
            name = "n") 

#FIXME !!! 
doubles <- filter(df, n>1) # no doubles (doubles were chamber-switchers)

doubles %>% kablebox()
agency icpsr chamber year perYear perYear_con perYear_pol congress party party_code state_abbrev district_code nominate.dim1 presidents_party female chair ranking_minority party_leader party_whip majority prestige prestige_chair yearelected state first_cong first_year tenure first second third fourth fifth sixth oversight_committee oversight_committee_chair icpsr_agency agency_year max_year survive n
Amtrak 14435 House 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA Amtrak_14435 Amtrak_2013 21 1 2
Amtrak 14435 House 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA Amtrak_14435 Amtrak_2013 21 1 2
Amtrak 14435 House 2014 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA Amtrak_14435 Amtrak_2014 21 1 2
Amtrak 14435 House 2014 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA Amtrak_14435 Amtrak_2014 21 1 2
Amtrak 14435 Senate 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA Amtrak_14435 Amtrak_2013 21 1 2
Amtrak 14435 Senate 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA Amtrak_14435 Amtrak_2013 21 1 2
Amtrak 14435 Senate 2014 1 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 0 0 Amtrak_14435 Amtrak_2014 21 1 2
Amtrak 14435 Senate 2014 1 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 0 0 Amtrak_14435 Amtrak_2014 21 1 2
Amtrak 20115 House 2009 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 8 0 0 0 0 0 0 NA NA Amtrak_20115 Amtrak_2009 15 1 2
Amtrak 20115 House 2009 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 8 0 0 0 0 0 0 NA NA Amtrak_20115 Amtrak_2009 15 1 2
Amtrak 20115 House 2010 1 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 9 0 0 0 0 0 0 0 0 Amtrak_20115 Amtrak_2010 15 1 2
Amtrak 20115 House 2010 1 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 9 0 0 0 0 0 0 0 0 Amtrak_20115 Amtrak_2010 15 1 2
Amtrak 20115 Senate 2009 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 8 0 0 0 0 0 0 NA NA Amtrak_20115 Amtrak_2009 15 1 2
Amtrak 20115 Senate 2009 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 8 0 0 0 0 0 0 NA NA Amtrak_20115 Amtrak_2009 15 1 2
Amtrak 20115 Senate 2010 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 9 0 0 0 0 0 0 NA NA Amtrak_20115 Amtrak_2010 15 1 2
Amtrak 20115 Senate 2010 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 9 0 0 0 0 0 0 NA NA Amtrak_20115 Amtrak_2010 15 1 2
Amtrak 20730 House 2011 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA Amtrak_20730 Amtrak_2011 11 1 2
Amtrak 20730 House 2011 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA Amtrak_20730 Amtrak_2011 11 1 2
Amtrak 20730 House 2012 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA Amtrak_20730 Amtrak_2012 11 1 2
Amtrak 20730 House 2012 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA Amtrak_20730 Amtrak_2012 11 1 2
Amtrak 20730 Senate 2011 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA Amtrak_20730 Amtrak_2011 11 1 2
Amtrak 20730 Senate 2011 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA Amtrak_20730 Amtrak_2011 11 1 2
Amtrak 20730 Senate 2012 1 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 0 0 Amtrak_20730 Amtrak_2012 11 1 2
Amtrak 20730 Senate 2012 1 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 0 0 Amtrak_20730 Amtrak_2012 11 1 2
Amtrak 20735 House 2009 1 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 0 0 Amtrak_20735 Amtrak_2009 11 1 2
Amtrak 20735 House 2009 1 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 0 0 Amtrak_20735 Amtrak_2009 11 1 2
Amtrak 20735 House 2010 0 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 NA NA Amtrak_20735 Amtrak_2010 11 1 2
Amtrak 20735 House 2010 0 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 NA NA Amtrak_20735 Amtrak_2010 11 1 2
Amtrak 20735 Senate 2009 0 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 NA NA Amtrak_20735 Amtrak_2009 11 1 2
Amtrak 20735 Senate 2009 0 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 NA NA Amtrak_20735 Amtrak_2009 11 1 2
Amtrak 20735 Senate 2010 2 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 0 0 Amtrak_20735 Amtrak_2010 11 1 2
Amtrak 20735 Senate 2010 2 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 0 0 Amtrak_20735 Amtrak_2010 11 1 2
Amtrak 29534 House 2007 0 0 0 110
200 MS 0 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 10 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2007 21 1 2
Amtrak 29534 House 2007 0 0 0 110
200 MS 1 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 10 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2007 21 1 2
Amtrak 29534 House 2008 0 0 0 110
200 MS 0 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2008 21 1 2
Amtrak 29534 House 2008 0 0 0 110
200 MS 1 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2008 21 1 2
Amtrak 29534 Senate 2007 0 0 0 110
200 MS 0 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 10 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2007 21 1 2
Amtrak 29534 Senate 2007 0 0 0 110
200 MS 1 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 10 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2007 21 1 2
Amtrak 29534 Senate 2008 0 0 0 110
200 MS 0 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2008 21 1 2
Amtrak 29534 Senate 2008 0 0 0 110
200 MS 1 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA Amtrak_29534 Amtrak_2008 21 1 2
CNCS 14435 House 2013 1 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 0 0 CNCS_14435 CNCS_2013 21 1 2
CNCS 14435 House 2013 1 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 0 0 CNCS_14435 CNCS_2013 21 1 2
CNCS 14435 House 2014 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CNCS_14435 CNCS_2014 21 1 2
CNCS 14435 House 2014 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CNCS_14435 CNCS_2014 21 1 2
CNCS 14435 Senate 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA CNCS_14435 CNCS_2013 21 1 2
CNCS 14435 Senate 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA CNCS_14435 CNCS_2013 21 1 2
CNCS 14435 Senate 2014 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CNCS_14435 CNCS_2014 21 1 2
CNCS 14435 Senate 2014 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CNCS_14435 CNCS_2014 21 1 2
CNCS 20115 House 2009 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 8 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2009 15 1 2
CNCS 20115 House 2009 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 8 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2009 15 1 2
CNCS 20115 House 2010 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 9 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2010 15 1 2
CNCS 20115 House 2010 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 9 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2010 15 1 2
CNCS 20115 Senate 2009 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 8 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2009 15 1 2
CNCS 20115 Senate 2009 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 8 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2009 15 1 2
CNCS 20115 Senate 2010 0 0 0 111
200 IL 0 0.274 0 0 0 0 0 0 NA 1 0 NA illinois 107 2001 9 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2010 15 1 2
CNCS 20115 Senate 2010 0 0 0 111
200 IL 10 0.274 0 0 0 0 0 0 0 1 0 2008 illinois 107 2001 9 0 0 0 0 0 0 NA NA CNCS_20115 CNCS_2010 15 1 2
CNCS 20730 House 2011 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CNCS_20730 CNCS_2011 11 1 2
CNCS 20730 House 2011 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CNCS_20730 CNCS_2011 11 1 2
CNCS 20730 House 2012 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CNCS_20730 CNCS_2012 11 1 2
CNCS 20730 House 2012 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CNCS_20730 CNCS_2012 11 1 2
CNCS 20730 Senate 2011 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CNCS_20730 CNCS_2011 11 1 2
CNCS 20730 Senate 2011 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CNCS_20730 CNCS_2011 11 1 2
CNCS 20730 Senate 2012 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CNCS_20730 CNCS_2012 11 1 2
CNCS 20730 Senate 2012 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CNCS_20730 CNCS_2012 11 1 2
CNCS 20735 House 2009 0 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 NA NA CNCS_20735 CNCS_2009 11 1 2
CNCS 20735 House 2009 0 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 NA NA CNCS_20735 CNCS_2009 11 1 2
CNCS 20735 House 2010 0 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 NA NA CNCS_20735 CNCS_2010 11 1 2
CNCS 20735 House 2010 0 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 NA NA CNCS_20735 CNCS_2010 11 1 2
CNCS 20735 Senate 2009 0 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 NA NA CNCS_20735 CNCS_2009 11 1 2
CNCS 20735 Senate 2009 0 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 2 0 0 1 0 0 0 NA NA CNCS_20735 CNCS_2009 11 1 2
CNCS 20735 Senate 2010 4 0 0 111
100 NY 0 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 0 0 CNCS_20735 CNCS_2010 11 1 2
CNCS 20735 Senate 2010 4 0 0 111
100 NY 20 -0.474 1 1 0 0 0 0 1 1 0 2008 new york 110 2007 3 0 0 0 1 0 0 0 0 CNCS_20735 CNCS_2010 11 1 2
CSOSA 14435 House 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2013 21 1 2
CSOSA 14435 House 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2013 21 1 2
CSOSA 14435 House 2014 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2014 21 1 2
CSOSA 14435 House 2014 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2014 21 1 2
CSOSA 14435 Senate 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2013 21 1 2
CSOSA 14435 Senate 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2013 21 1 2
CSOSA 14435 Senate 2014 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2014 21 1 2
CSOSA 14435 Senate 2014 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA CSOSA_14435 CSOSA_2014 21 1 2
CSOSA 20730 House 2011 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CSOSA_20730 CSOSA_2011 11 1 2
CSOSA 20730 House 2011 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CSOSA_20730 CSOSA_2011 11 1 2
CSOSA 20730 House 2012 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CSOSA_20730 CSOSA_2012 11 1 2
CSOSA 20730 House 2012 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CSOSA_20730 CSOSA_2012 11 1 2
CSOSA 20730 Senate 2011 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CSOSA_20730 CSOSA_2011 11 1 2
CSOSA 20730 Senate 2011 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 4 0 0 0 0 1 0 NA NA CSOSA_20730 CSOSA_2011 11 1 2
CSOSA 20730 Senate 2012 0 0 0 112
200 NV 0 0.463 0 0 0 0 0 0 0 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CSOSA_20730 CSOSA_2012 11 1 2
CSOSA 20730 Senate 2012 0 0 0 112
200 NV 2 0.463 0 0 0 0 0 0 1 1 0 2010 nevada 110 2007 5 0 0 0 0 0 1 NA NA CSOSA_20730 CSOSA_2012 11 1 2
CSOSA 29534 House 2008 0 0 0 110
200 MS 0 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA CSOSA_29534 CSOSA_2008 21 1 2
CSOSA 29534 House 2008 0 0 0 110
200 MS 1 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA CSOSA_29534 CSOSA_2008 21 1 2
CSOSA 29534 Senate 2008 0 0 0 110
200 MS 0 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA CSOSA_29534 CSOSA_2008 21 1 2
CSOSA 29534 Senate 2008 0 0 0 110
200 MS 1 0.376 1 NA 0 0 0 0 0 1 0 2006 mississippi 105 1997 11 0 0 0 0 0 0 NA NA CSOSA_29534 CSOSA_2008 21 1 2
DHHS_ACF 14435 House 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA DHHS_ACF_14435 DHHS_ACF_2013 21 1 2
DHHS_ACF 14435 House 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA DHHS_ACF_14435 DHHS_ACF_2013 21 1 2
DHHS_ACF 14435 House 2014 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA DHHS_ACF_14435 DHHS_ACF_2014 21 1 2
DHHS_ACF 14435 House 2014 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 NA NA DHHS_ACF_14435 DHHS_ACF_2014 21 1 2
DHHS_ACF 14435 Senate 2013 0 0 0 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA DHHS_ACF_14435 DHHS_ACF_2013 21 1 2
DHHS_ACF 14435 Senate 2013 0 0 0 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 16 0 0 0 0 0 0 NA NA DHHS_ACF_14435 DHHS_ACF_2013 21 1 2
DHHS_ACF 14435 Senate 2014 1 0 1 113
100 MA 0 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 0 0 DHHS_ACF_14435 DHHS_ACF_2014 21 1 2
DHHS_ACF 14435 Senate 2014 1 0 1 113
100 MA 5 -0.511 1 0 0 1 0 0 0 1 0 2012 massachusetts 105 1997 17 0 0 0 0 0 0 0 0 DHHS_ACF_14435 DHHS_ACF_2014 21 1 2
# drop doubles 
df %<>% filter(n<2) 


# LEVEL MODELS

df %<>% 
  # mutate(agency_year) %>% 
  mutate(lpyear = log(perYear + 1))

District-level

  • Were most maps in place by 2011?
####
# Redistricting? were most maps in place by 2011?
decade<- case_when(df$year < 2011 ~ '0', 
                   df$year > 2010 ~ '1')

state_dist<- case_when(df$chamber=='Senate'~ paste(df$state,
                                                    df$district_code, 
                                                    sep='_' ), 
                       df$chamber =='House'~ paste(paste(df$state, 
                                                          df$district_code, 
                                                          sep='_'), 
                                                    decade,
                                                    sep='_'))




df$state_dist<- state_dist

perDist<- df %>% 
  group_by(year, state_dist, icpsr, chamber, tenure, state) %>% 
  summarise(perYear = sum(perYear)) %>%
  distinct()



## Now, we want to identify when there is a new member in a district.  To do this, we look for changes in the icpsr number
perDist$new_member<- ifelse(perDist$tenure==0, 1, 0)

perDist$second_year<- ifelse(perDist$tenure==1, 1, 0)
perDist$third_year<- ifelse(perDist$tenure==2, 1, 0)
perDist$fourth_year<- ifelse(perDist$tenure==3, 1, 0)
perDist$fifth_year<- ifelse(perDist$tenure==4, 1, 0)
perDist$sixth_year<- ifelse(perDist$tenure==5, 1, 0)


state_level<- perDist %>% group_by(state, year) %>% 
  summarise(numpers = n(), 
            sumYear = sum(perYear), 
            mean_new = mean(new_member)) 

state_new <- ifelse(state_level$mean_new>0, 1, 0)

state_level$state_new <- state_new

perDist %<>% left_join(state_level %>% 
                         select(state_new, mean_new, state, year), 
                    by = c('state', 'year'))
#########################
# saved as DistrictLevel
########################
# save(perDist, file =  here::here("data", "perDist.Rdata"))
############################################

TODO

Priority

##creating the ratio variable 
d_rat <- df %>% 
  group_by(year, icpsr, chamber,
           prestige, prestige_chair, chair, ranking_minority, majority, presidents_party,
           first, second, third, fourth, fifth, sixth) %>% 
  # per member per year counts per type2
  summarise(perCon = sum(perYear_con), 
            perPol = sum(perYear_pol)) %>% 
  # ratio of con to pol 
  #FIXME switch? 
  mutate(ratio = perCon/(perCon + perPol))

# drop doubles
d_rat %<>% group_by(year, icpsr, chamber) %>% add_count(name = "n")

doubles_ratio <- filter(d_rat, n>1)

doubles_ratio %>% kablebox()
year icpsr chamber prestige prestige_chair chair ranking_minority majority presidents_party first second third fourth fifth sixth perCon perPol ratio n
d_rat %<>% filter(n<2) 

############################################
# d_rat saved as ProportionContact.dta')
# save(d_rat, file =  here::here("data", "d_rat.Rdata"))
############################################

# RATIO MODEL 

TODO

Joint Effect of Capacity and Priority

We observe the total requests, \(z\), and ratio, \(r\), of policy work to constituency service. \(z\) is the sum of policy requests \(x\) and constituency service requests \(y\). \(r\) is \(x/y\)./

r = .2

r2 = .31

z = 100

x = z*r
y = z-z*r


z2 = 120

x2 = z2*r2
y2 = z2-z2*r2

Combining model estimates for the shift in the level of requests and relative priority of policy work to constituency service, we see that even as the ratio of policy work increases, constituency service also significantly increases.

These estimates are calculated by adding diff-in-diff regression coefficients for committee chairs’ increased levels of requests to the baseline levels for non-chairs. We also adjust the ratio of policy work to constituency service based on the diff-in-diff regression coefficients for committee chairs’ increased policy work ratio.

n_agencies <- dcounts_min$agency %>% unique() %>% length()

#FIXME replace with tidy model output 
# TABLE 1
level <- tribble(~term, ~estimate, ~std.error,
                 "chair", 0.206, 0.0951)

# per member across all agencies 
level$estimate <- level$estimate*n_agencies
level$std.error <- level$std.error*n_agencies

# ratio of policy work for non-chairs
base_ratio <- chair$mean[3]/chair$mean[1]

# level estimates with baseline ratio (for presenting level effects only)
level_con <- level %>% mutate(estimate = estimate*(1-base_ratio),
                               std.error = std.error*(1-base_ratio))

level_pol <- level %>% mutate(estimate = estimate*(base_ratio),
                               std.error = std.error*(base_ratio))


# Priority Table 
priority <- tribble(~term, ~estimate, ~std.error,
                 "chair", 0.0875, 0.0175)

# adjust level estimates with new ratio (joint effects )
new_ratio <- base_ratio + priority$estimate[1]

level_con <- level %>% mutate(estimate = estimate*(1-new_ratio),
                               std.error = std.error*(1-new_ratio))

level_pol <- level %>% mutate(estimate = estimate*(new_ratio),
                               std.error = std.error*(new_ratio))


#FIXME, include priority model uncertianty too
chair$std.error <- NA
# constituent error 
chair$std.error[2] <- level_con$std.error[1]
# policy error
chair$std.error[4] <- level_pol$std.error[1]


# chair mean = non-chair mean * level coef
# constituent estimate 
chair$mean[2] <- chair$mean[1] + (1 + level_con$estimate[1] )
# policy estimate
chair$mean[4] <- chair$mean[3] + (1+level_pol$estimate[1] )

chair_adjusted <- chair %>% 
  # assuming consistant proportions to uncoded data 
  mutate(mean = mean*multiplier) %>%
  # baseline = non-chairs mean
  mutate(baseline = ifelse(Chair == "Committee Chair", NA, mean) ) %>%
  fill(baseline) %>%
  # point estimates and uncertiatty only for chair estimates 
  mutate(estimate = ifelse(Chair == "Committee Chair", mean, NA)) %>% 
  mutate(std.error = ifelse(Chair == "Committee Chair", std.error, NA)) 

chair_adjusted %>% 
  #mutate(Chair = ifelse() )
  ggplot()  + 
  aes(x = type, y = mean) +
  geom_col(alpha = .7, position = "dodge") + 
  geom_hline(aes(yintercept = baseline), linetype = 2) + 
  geom_pointrange(aes(y = estimate,
                      ymin = mean-1.96*std.error,
                      ymax = mean+1.96*std.error)) + 
  facet_wrap("Chair") + 
  labs(x = "", #Type of Legislator Request to Agency",
       y = "Average Requests per Year") +
  theme(panel.grid.major.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.x = element_blank())
Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

chair_adjusted %<>% mutate(baseline = ifelse(type =="Constituency\nService", baseline+ 12.4, baseline))


# stacked to show ratio with PERCENTS 
chair_adjusted %>% 
  #mutate(Chair = ifelse() )
  ggplot()  + 
  aes(x = Chair, y = mean, fill = type) +
  geom_col(alpha = .7, position = "fill") +  
  facet_wrap("Chair", scales = "free_x") + 
  labs(x = "", #Type of Legislator Request to Agency",
       y = "Share of Requests per Year",
       fill = "") +
  theme(panel.grid.major.x = element_blank(),
        axis.text.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.x = element_blank())
Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

# stacked to show ratio + free scales 
chair_adjusted %>% 
  #mutate(Chair = ifelse() )
  ggplot()  + 
  aes(x = Chair, y = mean, fill = type) +
  geom_col(alpha = .7, position = "stack") + 
  #geom_hline(aes(yintercept = baseline), linetype = 2) + 
  #geom_pointrange(aes(y = estimate,
                      #ymin = mean-1.96*std.error,
                      #ymax = mean+1.96*std.error)) + 
  facet_wrap("Chair", scales = "free") + 
  #scale_y_
  labs(x = "", #Type of Legislator Request to Agency",
       y = "Average Requests per Year",
       fill = "") +
  theme(panel.grid.major.x = element_blank(),
        axis.text.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.x = element_blank())
Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

# stacked to show ratio + CI
chair_adjusted %>% 
  #mutate(Chair = ifelse() )
  ggplot()  + 
  aes(x = Chair, y = mean, fill = type) +
  geom_col(alpha = .7, position = "stack") + 
  geom_hline(aes(yintercept = baseline), linetype = 2) + 
  geom_pointrange(aes(y = estimate,
                      ymin = mean-1.96*std.error,
                      ymax = mean+1.96*std.error)) + 
  facet_wrap("Chair", scales = "free") + 
  labs(x = "", #Type of Legislator Request to Agency",
       y = "Average Requests per Year",
       fill = "") +
  theme(panel.grid.major.x = element_blank(),
        axis.text.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.x = element_blank())
Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

Difference-in-Difference Estimates of Change in Levels of Constituency Service and Policy Work as Legislators Gain Power

The baseline level (non-chairs) is 55.3494555 constituency service requests and 12.404877 policy requests per year.

The baseline ratio (for non-chairs) of policy work to constituency service is 0.2241192. Adding the model coefficient from the difference in difference model of shifting priorities yields a new ratio of 0.3116192.

The model-estimated level for committee chairs is 72.8128495 constituency service requests and 21.0047737 policy requests per year.

#TODO

  • intercoder agrement for USTR

  • y-axis label and remove the title from inequality figure

  • facet distribution across types by policy and constituent, probably coord flip as well

  • [ x ] remove the title from state pop figure